﻿using System;
using System.Collections.Generic;
using System.Data;
using Ue.Framework.Data;
using Ue.Infrastructure.EntityFactoryFramework;
using Ue.Qcdz.Domain.TreeViews;

namespace Ue.Qcdz.Repositories.TreeViews
{
    public class TreeNodeFactory : IEntityFactory<TreeNode>
    {
        public const string TableName = "TreeNodes";

        internal class FieldNames : FieldNamesBase
        {
            public const string TreeViewInNodes = "TreeViewId";
            public const string TagInNodes = "TagId";
            public const string ParentId = "ParentId";
            public const string DisplayOrder = "DisplayOrder";
            public const string TagFullType = "TagFullType";
            //public const string TagRepositoryInterfaceFulType = "TagRepositoryInterfaceFulType";
        }

        public TreeNode BuildEntity(IDataReader reader)
        {
            return new TreeNodeProxy(
                reader.Get<Guid>(FieldNames.EntityKey),
                reader.Get<Guid?>(FieldNames.ParentId),
                reader.Get<int>(FieldNames.DisplayOrder),
                reader.Get<DateTime>(FieldNames.CreateOn))
                {
                    TagType = reader.Get<Type>(FieldNames.TagFullType)
                };
        }
    }
}
